<?php
	require_once('../../execute/inc/config.inc');
	$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
	if(!$link) {
		die('Failed to connect to server: ' . mysql_error());
	}
	
	//Select database
	$db = mysql_select_db(DB_DATABASE);
	if(!$db) {
		die("Unable to select database");
	}
	$qry = mysql_query("SELECT * FROM courses WHERE id='".$_GET['cid']."'");
	$row = mysql_fetch_array($qry);
?>
<hr>
<h3><?php echo $row['course_title']; ?></h3>
<p><?php echo $row['description']; ?></p>
<div class="row-fluid">
	<div class="span4" style="border-right:1px solid #E3DCDE; padding-right:20px;"><h4>General</h4>
		<div class="alert alert-info">
			<table class="table">
				<tr style=""><th>Start Date</th><th>End Date</th></tr>
				<tr><td><?php echo $row['startdate']; ?></td><td><?php echo $row['finishdate']; ?></td></tr>
				<tr><th>Address</th><th>&nbsp;</th></tr>
				<tr><td colspan="2"><?php echo $row['address']; ?></td></tr>
			</table>
		</div>
	</div>
	<?php 
	 $material_file_select = mysql_query("SELECT * FROM course_materials WHERE type='file' AND course_id='".$_GET['cid']."'");
	 $material_link_select = mysql_query("SELECT * FROM course_materials WHERE type='link' AND course_id='".$_GET['cid']."'");
	?>
		<div class="span4" style="border-right:1px solid #E3DCDE; padding-right:20px;">
		<h4>Materials</h4>
	<?php
	if(mysql_num_rows($material_file_select)==0){
		?>
		No Materials Found.
		<?php
	}
	else { ?>
		
		<table class="table table-hover">
			<tr><th>#</th><th>Name</th><th>Description</th><th>Download</th></tr>
			<?php $count = 1; 
			while ($material_file_row = mysql_fetch_array($material_file_select)){ 
				$file = mysql_query("SELECT file_name FROM material_file WHERE material_id = '".$material_file_row['material_id']."'");
				$file_row = mysql_fetch_array($file); ?>
				<tr>
				<td><?php echo $count; ?></td>
				<td><?php echo $material_file_row['name']; ?></td>
				<td><?php echo $material_file_row['description']; ?></td>
				<td><a href="execute/download.php?file=<?php echo $file_row[0];?>" style="margin-left:25px;"><i class="icon-download-alt"></i></a></td>
				</tr>
			<?php $count++; 
			}?>		
		</table>
	
	<?php } ?>
	</div>
	<div class="span4">
		<h4>Usefull Links</h4>
		<?php
	if(mysql_num_rows($material_link_select)==0){
		?>
		No Links Found.
		<?php
	}
	else { ?>
		<table class="table table-hover">
			<tr><th>#</th><th>Name</th><th>Description</th><th>URL</th></tr>
			<?php $count = 1; 
			while ($material_link_row = mysql_fetch_array($material_link_select)){ 
				$link = mysql_query("SELECT url FROM material_link WHERE material_id = '".$material_link_row['material_id']."'");
				$link_row = mysql_fetch_array($link); ?>
				<tr>
				<td><?php echo $count; ?></td>
				<td><?php echo $material_link_row['name']; ?></td>
				<td><?php echo $material_link_row['description']; ?></td>
				<td><a target="_blank" href="<?php echo $link_row[0]; ?>"><?php echo $link_row[0]; ?></a></td>
				</tr>
			<?php $count++; 
			}?>		
		</table>
		<?php } ?>
	</div>
</div>